<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib  prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib  prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="sysConfigDataUrl" value="${redis:getSysConfig('sync_sysConfigDataUrl')}"/>
<c:set var="keyBookDataUrl" value="${redis:getSysConfig('sync_keyBookDataUrl')}"/>
<c:set var="phoneKeyBookUrl" value="${redis:getSysConfig('sync_phoneKeyBookUrl')}"/>
<c:set var="productTypeUrl" value="${redis:getSysConfig('sync_productTypeUrl')}"/>
<c:set var="homeKeyBookUrl" value="${redis:getSysConfig('sync_homeKeyBookUrl')}"/>
<c:set var="homeDynamicPreview" value="${redis:getSysConfig('sync_homeDynamicPreview')}"/>
<c:set var="generateStaticPage" value="${redis:getSysConfig('sync_generateStaticPage')}"/>
<c:set var="navigationOrTopSearch" value="${redis:getSysConfig('sync_navigationOrTopSearch')}"/>
<c:set var="article" value="${redis:getSysConfig('sync_article')}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
	<head>
		<title>同步数据信息</title>
		<jsp:include page="../../util/import.jsp"/>
	</head>
	<style type="text/css">
		#buttons{
			margin-top: 100px;
			margin-left: auto;
			margin-right: auto;
			width:960px;

		}
		.btn-group{margin-left: 40px;}
		.split{height:40px;}
		.resultInfo{font-size: 16px;}
	</style>
	<script type="text/javascript">
		/**数据字典路径**/
        var keyBookDataUrl = '${keyBookDataUrl}';
        /**系统配置路径**/
        var sysConfigDataUrl = '${sysConfigDataUrl}';
        /**手机数据字典路径**/
        var phoneKeyBookUrl = '${phoneKeyBookUrl}';
        /**商品分类路径**/
        var productTypeUrl = '${productTypeUrl}';
        /**首页数据字典路径**/
        var homeKeyBookUrl = '${homeKeyBookUrl}';
        /**商城首页动态预览路径**/
        var homeDynamicPreview = '${homeDynamicPreview}';
        /**商城首页静态化路径**/
        var generateStaticPage = '${generateStaticPage}';
        /**首页导航条及热搜关键字路径**/
        var navigationOrTopSearch = '${navigationOrTopSearch}';
        /**商城首页底部文章路径**/
        var article = '${article}';

        /**首页动态页预览**/
		<shiro:hasPermission name="back_gotoSyncDataPage_homePage">
        $(function() {
            $("#homePage").click(function(){
                window.open(homeDynamicPreview);
            });
        });
		</shiro:hasPermission>

        /**同步【商城首页】初始化信息**/
		<shiro:hasPermission name="back_gotoSyncDataPage_homeUpdate">
        $(function() {
            $("#homeUpdate").click(function(){
                $(this).button('loading').delay(1000).queue(function() {
                    $.ajax({
                        type: "GET",
                        dataType: "JSON",
                        url:generateStaticPage,
                        success: function (data) {
                            if(data.success){
                                resetBtn("#homeUpdate","同步数据成功");
                            }else{
                                resetBtn("#homeUpdate","同步数据失败");
                            }
                        },
                        error:function (XMLHttpRequest, textStatus, errorThrown){
                            resetBtn("#homeUpdate","同步数据失败");
                        }
                    });
                });
            });
        });
		</shiro:hasPermission>

        /**同步数据字典方法**/
		<shiro:hasPermission name="back_gotoSyncDataPage_syncKeyBook">
        $(function() {
            $("#syncBasicKeyBook").click(function(){
                $(this).button('loading').delay(1000).queue(function() {
                    $.ajax({
                        type: "GET",
                        dataType: "JSON",
                        url:keyBookDataUrl,
                        success: function (data) {
                            if(data.success){
                                resetBtn("#syncBasicKeyBook","同步数据成功");
                            }else{
                                resetBtn("#syncBasicKeyBook","同步数据失败");
                            }
                        },
                        error:function (XMLHttpRequest, textStatus, errorThrown){
                            resetBtn("#syncBasicKeyBook","同步数据失败");
                            console.log(textStatus);
                    	}
               		 });
                });
            });
        });
		</shiro:hasPermission>

        /**同步系统配置方法**/
		<shiro:hasPermission name="back_gotoSyncDataPage_syncSystemConfig">
        $(function() {
            $("#syncSystemConfig").click(function(){
                $(this).button('loading').delay(1000).queue(function() {
                    $.ajax({
                        type: "GET",
                        dataType: "JSON",
                        url:sysConfigDataUrl,
                        success: function (data) {
                            if(data.success){
                                resetBtn("#syncSystemConfig","同步数据成功");
                            }else{
                                resetBtn("#syncSystemConfig","同步数据失败");
                            }
                        },
                        error:function (XMLHttpRequest, textStatus, errorThrown){
                            resetBtn("#syncSystemConfig","同步数据失败");
                        }
                    });
                });
            });
        });
		</shiro:hasPermission>

        /**同步首页数据字典方法**/
		<shiro:hasPermission name="back_gotoSyncDataPage_syncHomeKeyBook">
        $(function() {
            $("#syncHomeKeyBook").click(function(){
                $(this).button('loading').delay(1000).queue(function() {
                    $.ajax({
                        type: "GET",
                        dataType: "JSON",
                        url:homeKeyBookUrl,
                        success: function (data) {
                            if(data.success){
                                resetBtn("#syncHomeKeyBook","同步数据成功");
                            }else{
                                resetBtn("#syncHomeKeyBook","同步数据失败");
                            }
                        },
                        error:function (XMLHttpRequest, textStatus, errorThrown){
                            resetBtn("#syncHomeKeyBook","同步数据失败");
                        }
                    });
                });
            });
        });
		</shiro:hasPermission>

        /**同步手机数据字典方法**/
		<shiro:hasPermission name="back_gotoSyncDataPage_syncPhoneHomeKeyBook">
        $(function() {
            $("#syncPhoneHomeKeyBook").click(function(){
                $(this).button('loading').delay(1000).queue(function() {
                    $.ajax({
                        type: "GET",
                        dataType: "JSON",
                        url:phoneKeyBookUrl,
                        success: function (data) {
                            if(data.success){
                                resetBtn("#syncPhoneHomeKeyBook","同步数据成功");
                            }else{
                                resetBtn("#syncPhoneHomeKeyBook","同步数据失败");
                            }
                        },
                        error:function (XMLHttpRequest, textStatus, errorThrown){
                            resetBtn("#syncPhoneHomeKeyBook","同步数据失败");
                        }
                    });
                });
            });
        });
		</shiro:hasPermission>

        /**同步商品分类方法**/
		<shiro:hasPermission name="back_gotoSyncDataPage_syncProductType">
        $(function() {
            $("#syncProductType").click(function(){
                $(this).button('loading').delay(1000).queue(function() {
                    $.ajax({
                        type: "GET",
                        dataType: "JSON",
                        url:productTypeUrl,
                        success: function (data) {
                            if(data.success){
                                resetBtn("#syncProductType","同步数据成功");
                            }else{
                                resetBtn("#syncProductType","同步数据失败");
                            }
                        },
                        error:function (XMLHttpRequest, textStatus, errorThrown){
                            resetBtn("#syncProductType","同步数据失败");
                        }
                    });
                });
            });
        });
		</shiro:hasPermission>

        /**同步首页导航条及热搜关键字方法**/
		<shiro:hasPermission name="back_gotoSyncDataPage_syncNavigationOrTopSearch">
        $(function() {
            $("#syncNavigationOrTopSearch").click(function(){
                $(this).button('loading').delay(1000).queue(function() {
                    $.ajax({
                        type: "GET",
                        dataType: "JSON",
                        url:navigationOrTopSearch,
                        success: function (data) {
                            if(data.success){
                            	resetBtn("#syncNavigationOrTopSearch","同步数据成功");
							}else{
                                resetBtn("#syncNavigationOrTopSearch","同步数据失败");
							}
                        } ,
                        error:function (XMLHttpRequest, textStatus, errorThrown){
                            resetBtn("#syncNavigationOrTopSearch","同步数据失败");
                        }
                    });
                });
            });
        });
		</shiro:hasPermission>

        /**同步商城底部新闻方法**/
		<shiro:hasPermission name="back_gotoSyncDataPage_syncArticle">
        $(function() {
            $("#syncArticle").click(function(){
                $(this).button('loading').delay(1000).queue(function() {
                    $.ajax({
                        type: "GET",
                        dataType: "JSON",
                        url:article,
                        success: function (data) {
                            if(data.success){
                            	resetBtn("#syncArticle","同步数据成功");
							}else{
                            	resetBtn("#syncArticle","同步数据成功");
							}
                        } ,
                        error:function (XMLHttpRequest, textStatus, errorThrown){
                            resetBtn("#syncArticle","同步数据失败");
                        }
                    });
                });
            });
        });
		</shiro:hasPermission>

        /**重置同步按钮方法 id为button Id，message为按钮提示语**/
		function resetBtn(id,message){
			$(id).html("<span class='resultInfo'>"+message+"</span>");
			/**延迟三秒重置同步按钮**/
			setTimeout(function(){
				$(id).dequeue();
				$(id).button('reset')
			},3000);
		}
	</script>
	<body>
	<div class="panel-body" id="buttons">
		<!-- 工具栏 -->
		<div class="btn-group">
			<shiro:hasPermission name="back_gotoSyncDataPage_homePage">
				<button id="homePage" type="button" class="btn btn-primary" data-loading-text="页面生成中...">
					<span class="badge pull-right">1</span>
					<span class="glyphicon glyphicon-arrow-up"></span>首页动态生成并预览
				</button>
			</shiro:hasPermission>
		</div>

		<div class="btn-group">
			<shiro:hasPermission name="back_gotoSyncDataPage_homeUpdate">
			<button id="homeUpdate" type="button" class="btn btn-primary" data-loading-text="数据同步中...">
				<span class="badge pull-right">2</span>
				<span class="glyphicon glyphicon-arrow-up"></span>同步【商城首页】初始化信息
			</button>
		</shiro:hasPermission>
		</div>

		<div class="btn-group">
			<shiro:hasPermission name="back_gotoSyncDataPage_syncNavigationOrTopSearch">
				<button id="syncNavigationOrTopSearch" type="button" class="btn btn-primary" data-loading-text="数据同步中...">
					<span class="badge pull-right">3</span>
					<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>同步导航条及热搜关键字数据
				</button>
			</shiro:hasPermission>
		</div>

		<div class="split"></div>
		<div class="btn-group">
			<shiro:hasPermission name="back_gotoSyncDataPage_syncKeyBook">
				<button id="syncBasicKeyBook" type="button" class="btn btn-primary" data-loading-text="数据同步中...">
					<span class="badge pull-right">4</span>
					<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>同步基础数据字典数据
				</button>
			</shiro:hasPermission>
		</div>

		<div class="btn-group">
			<shiro:hasPermission name="back_gotoSyncDataPage_syncHomeKeyBook">
				<button id="syncHomeKeyBook" type="button" class="btn btn-primary" data-loading-text="数据同步中...">
					<span class="badge pull-right">5</span>
					<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>同步首页数据字典数据
				</button>
			</shiro:hasPermission>
		</div>

		<div class="btn-group">
			<shiro:hasPermission name="back_gotoSyncDataPage_syncPhoneHomeKeyBook">
				<button id="syncPhoneHomeKeyBook" type="button" class="btn btn-primary" data-loading-text="数据同步中...">
					<span class="badge pull-right">6</span>
					<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>同步手机数据字典数据
				</button>
			</shiro:hasPermission>
		</div>
		<div class="split"></div>
		<div class="btn-group">
			<shiro:hasPermission name="back_gotoSyncDataPage_syncSystemConfig">
				<button id="syncSystemConfig" type="button" class="btn btn-primary" data-loading-text="数据同步中...">
					<span class="badge pull-right">7</span>
					<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>同步系统配置数据
				</button>
			</shiro:hasPermission>
		</div>

		<div class="btn-group">
			<shiro:hasPermission name="back_gotoSyncDataPage_syncProductType">
				<button id="syncProductType" type="button" class="btn btn-primary" data-loading-text="数据同步中...">
					<span class="badge pull-right">8</span>
					<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>同步商品分类数据
				</button>
			</shiro:hasPermission>
		</div>

		<div class="btn-group">
			<shiro:hasPermission name="back_gotoSyncDataPage_syncArticle">
				<button id="syncArticle" type="button" class="btn btn-primary" data-loading-text="数据同步中...">
					<span class="badge pull-right">9</span>
					<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>同步新闻数据
				</button>
			</shiro:hasPermission>
		</div>
	</div>
	<script type="text/javascript">
		$(function(){
		    $(".btn").css("height","80px").css("width","260px").css("font-size","14px");
		});
	</script>
	</body>
</html>
